package org.sag.mallbf;

import org.sag.mallbf.type.DataType;

import java.io.DataOutputStream;
import java.util.ArrayList;

/**
 * Segment Spec
 *
 * --> Version
 * Int16 Type: SEGMENT
 * Int16 Version = 4
 *
 * --> Version Info
 * Int32 Group Count (inc VGroup)
 *
 * --> Trunk Area
 */
public class ObjSegment {

    VGroup vs;
    ArrayList<EGroup> gs;

    public ObjSegment() {
        vs = new VGroup();
        gs = new ArrayList<>();
    }

    public void exportTo(DataOutputStream dos, int version) throws Exception {
        //Type
        Utils.putShort(dos, (short) DataType.SEGMENT.getValue(), 0);
        Utils.putShort(dos, (short) version, 0);

        Utils.putInt(dos, 1 + gs.size(), 1);

        vs.exportTo(dos, version);

        for (EGroup g : gs) {
            g.exportTo(dos, version);
        }
    }
}
